/*
* var buf=new Buffer(5);//废弃的
* var buf=Buffer.alloc(10);//代替者
* var buf=Buffer.allocUnsafe(10);
* */


/*
var buf=new Buffer("this is buffer","utf-8"); //废弃的
var buf=Buffer.from("this is buffer","utf-8");//代替者
*/
/*
* var buf=new Buffer([1,2,3,4,5]);//废弃的
* var buf=Buffer.from([1,2,3,4,5]);
* */



/*
console.log(buf);*/

/*
    buf.write(string,offet,length,encoding)
*  var buf=Buffer.alloc(20);
 buf.write("你好吗，你好",2,6,"utf-8");
 console.log(buf);
*
* */

/*
* buf.toString();
*  var buf=Buffer.from("你好","utf-8");
 console.log(buf.toString("utf-8",3));
* */

/*
*  buf.toJson
*  var buf=Buffer.from("this is Buffer");
 var jsonBuf=buf.toJSON();
 console.log(jsonBuf);
 for(var i=0;i<jsonBuf.data.length;i++){
 console.log(String.fromCharCode(jsonBuf.data[i]))
 }
* */

/*
* buf.slice() 截取buffer 对象。
* var buf=Buffer.from("zhangyingcai");
 var buf1= buf.slice(3,6);
 console.log(buf1);
 for(var i=0;i<buf1.length;i++){
 console.log(String.fromCharCode(buf1[i]));
 }
 *
* */


/*
*  buf.copy();
* */

 var buf=Buffer.from("this is Buffer");
 var buf1=Buffer.alloc(26);
 var buf2=buf.copy(buf1);
 console.log(buf1)


